- /* sdflog1x.cpp by K.Tsuru */
- // function ID 3403
- /***********************************************************************
- SDouble class
- It provides the natulal logalithm by the series
- calculate log(1-x) = -x(1 + x/2 + x^2/3 +....) = Log1_X(x),
- where |x| must be much less than one(|x|<1.0/DRADIX) and 'x' can be negative.
- It is better to use the series
- log(1-x) = -(x + x^2/2 + x^3/3 +....)
- for the precision.
- ************************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static const char* const func = "Log1_X";
- SDouble Log1_X(const SDouble& x){
- SDouble sum(x), xn(x*x), delta;
-
- if(x.NetRdxExp() >= 0) x.SetError(x.OUT_OF_RANGE, func, 3403);
-
- sum.FixedPoint(sum.RdxExp());
- ulong k = 2, mt = x.SlOpMaxValue();
-
- do{
- delta = DsDiv(xn, k);
- if(delta.Sign(3403) == 0) break;
- sum += delta;
- xn *= x;
- if( (k++) >= mt ){
- sum.SetError(sum.NOT_CONVERGE, func, -3403);
- break;
- }
- }while(xn.Sign(3403));
-
- sum.PointFree();
- sum.Reform(3403);
- x.upToTerm = k;
- sum.ChangeSign();
- return sum;
- }
sdflog1x.cpp : last modifiled at 2015/12/03 21:42:16(1,097 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).